package io.jt808.proto.req;

import io.norland.buffer.AutoBuffer;
import io.norland.annotations.Proto;
import io.norland.proto.IProto;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * 摄像头立即拍摄命令应答
 */
@Proto("0805")
@Data
public class JT0805 implements IProto {
    /**
     * 应答消息流水号
     */
    private int responseMessageSerialNo;

    /**
     * 结果
     */
    private byte result;
    private short mediaNum;
    private List<Integer> mediaIdList;

    public byte[] writeToBytes() {
        AutoBuffer buffer = new AutoBuffer();
        buffer.writeShort(responseMessageSerialNo);
        buffer.writeByte(result);
        buffer.writeShort(mediaNum);
        for (Integer id:mediaIdList){
            buffer.writeInt(id);
        }
        return buffer.array();
    }

    public void readFromBuf(AutoBuffer buffer) {
        responseMessageSerialNo = buffer.readShort();
        result = buffer.readByte();
        mediaNum = buffer.readShort();
        mediaIdList = new ArrayList<>();
        while (buffer.isReadable()) {
            mediaIdList.add(buffer.readInt());
        }
    }


//    public static void main(String[] args) {
//        byte[] bytes = new byte[]{
//                0x00, 0x01,
//                0x02,
//                0x00,0x03,
//                0x00, 0x00, 0x00, 0x00,
//                0x00, 0x00, 0x00, 0x03,
//                0x01, 0x59, 0x5e,0x32,
//        };
//        AutoBuffer buffer = new AutoBuffer(bytes);
//        JT0805 jt8003 = new JT0805();
//        jt8003.readFromBuf(buffer);
//        System.out.printf(new String(bytes).equals(new String(jt8003.writeToBytes())) + "");
//    }
}